import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'package:flutter/material.dart';
import 'package:learning/IconFontIcons.dart';
import 'package:learning/pages/IndexPage.dart';
import 'package:learning/pages/UserPage.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _cuttentIndex = 0;
  GlobalKey<CurvedNavigationBarState> _bottomNavigationKey = GlobalKey();

  List pages = [const IndexPage(), const UserPage()];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void didUpdateWidget(MyHomePage oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Container(
      color: Colors.black.withAlpha(12),
      child: Scaffold(
        /*  bottomNavigationBar: BrnBottomTabBar(
        fixedColor: Colors.blue,
        currentIndex: _cuttentIndex,
        onTap: (int index) {
      _cuttentIndex = index;
      print('index = $index');
      setState(() {}); //刷新状态
    },
        badgeColor: Colors.red,
        items: <BrnBottomTabBarItem>[
    BrnBottomTabBarItem(
        icon: Icon(IconFontIcons.iconAVoice21,color: Colors.black38,size: 30.0),activeIcon:Icon(IconFontIcons.iconAVoice21,color: Colors.blue,size: 30.0), title: MyText(S.of(context).kaoshi)),
    BrnBottomTabBarItem(icon:Icon(IconFontIcons.iconAVoice21,color: Colors.black38,size: 30.0),activeIcon:Icon(IconFontIcons.iconAVoice21,color: Colors.blue,size: 30.0), title: MyText(S.of(context).wo))

    ])*/
        bottomNavigationBar: CurvedNavigationBar(
          key: _bottomNavigationKey,
          index: 0,
          height: 50.0,
          items: <Widget>[
            Icon(IconFontIcons.iconAutoDrive, size: 30, color: Colors.blue.shade700),
            Icon(IconFontIcons.iconPowerRecycle, size: 30, color: Colors.blue.shade700)
          ],
          color: Colors.blue.shade100,
          buttonBackgroundColor: Colors.blue.shade100,
          backgroundColor: Colors.black.withAlpha(12),

          animationCurve: Curves.easeInOut,
          animationDuration: Duration(milliseconds: 600),
          onTap: (index) {
            setState(() {
              _cuttentIndex = index;
            });
          },
          letIndexChange: (index) => true,
        ),
        body: pages[_cuttentIndex], //传入数据源数组中对应index的控制器即可
      ),
    );
  }
}
